using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Data.SqlClient;

using SIS.ENT;

/// <summary>
/// The TeacherOtherSkillsTableDB class is responsible for interacting with the database to retrieve and store information
/// about TeacherOtherSkillsTable objects.
/// </summary>
public class TeacherOtherSkillsTableDB

{
#region "Public Methods"

/// <summary>
/// Gets an instance of TeacherOtherSkillsTable from the underlying datasource.
/// </summary>
/// <param name="teacherOtherSkillsKey">The unique TeacherOtherSkillsKey of the TeacherOtherSkillsTable in the database.</param>
/// <returns>An TeacherOtherSkillsTable when the TeacherOtherSkillsKey was found in the database, or null otherwise.</returns>
public static TeacherOtherSkillsTable GetItem(int teacherOtherSkillsKey)
{
TeacherOtherSkillsTable myTeacherOtherSkillsTable = null;
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
{
using (SqlCommand myCommand = new SqlCommand("sprocTeacherOtherSkillsTableSelectSingleItem", myConnection))
{
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.AddWithValue("@teacherOtherSkillsKey", teacherOtherSkillsKey);

myConnection.Open();
using (SqlDataReader myReader = myCommand.ExecuteReader())
{
if (myReader.Read()) {
myTeacherOtherSkillsTable = FillDataRecord(myReader);
}
myReader.Close();
}
myConnection.Close();
}
return myTeacherOtherSkillsTable;
}
}

/// <summary>
/// Returns a list with TeacherOtherSkillsTable objects.
/// </summary>
/// <returns>A generics List with the TeacherOtherSkillsTable objects.</returns>
public static TeacherOtherSkillsTableList GetList()
{
TeacherOtherSkillsTableList tempList = new TeacherOtherSkillsTableList();
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
{
using (SqlCommand myCommand = new SqlCommand("sprocTeacherOtherSkillsTableSelectList", myConnection))
{
myCommand.CommandType = CommandType.StoredProcedure;

myConnection.Open();
using (SqlDataReader myReader = myCommand.ExecuteReader())
{
if (myReader.HasRows)
{
while (myReader.Read())
{
tempList.Add(FillDataRecord(myReader));
}
}
myReader.Close();
}
}
}
return tempList;
}

public static TeacherOtherSkillsTableList GetList(int UserAccountKey)
{
    TeacherOtherSkillsTableList tempList = new TeacherOtherSkillsTableList();
    using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
    {
        using (SqlCommand myCommand = new SqlCommand("sprocTeacherOtherSkillsTableSelectList", myConnection))
        {
            myCommand.CommandType = CommandType.StoredProcedure;
            myCommand.Parameters.AddWithValue("@UserAccountKey", UserAccountKey);

            myConnection.Open();
            using (SqlDataReader myReader = myCommand.ExecuteReader())
            {
                if (myReader.HasRows)
                {
                    while (myReader.Read())
                    {
                        tempList.Add(FillDataRecord(myReader));
                    }
                }
                myReader.Close();
            }
        }
    }
    return tempList;
}

/// <summary>
/// Returns a list with TeacherOtherSkillsTable objects.
/// </summary>
/// <returns>A generics List with the TeacherOtherSkillsTable objects.</returns>
public static TeacherOtherSkillsTableList GetListByUserAccountKey(int UserAccountKey)
{
TeacherOtherSkillsTableList tempList = new TeacherOtherSkillsTableList();
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
{
using (SqlCommand myCommand = new SqlCommand("sprocTeacherOtherSkillsTableSelectListByUserAccountKey", myConnection))
{
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.AddWithValue("@userAccountKey", UserAccountKey);
myConnection.Open();
using (SqlDataReader myReader = myCommand.ExecuteReader())
{
if (myReader.HasRows)
{
while (myReader.Read())
{
tempList.Add(FillDataRecord(myReader));
}
}
myReader.Close();
}
}
return tempList;
}
}

/// <summary>
/// Saves a TeacherOtherSkillsTable in the database.
/// </summary>
/// <param name="myTeacherOtherSkillsTable">The TeacherOtherSkillsTable instance to save.</param>
/// <returns>The new TeacherOtherSkillsKey if the TeacherOtherSkillsTable is new in the database or the existing TeacherOtherSkillsKey when an item was updated.</returns>
public static int Save(TeacherOtherSkillsTable myTeacherOtherSkillsTable)
{
int result = 0;
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
{
using (SqlCommand myCommand = new SqlCommand("sprocTeacherOtherSkillsTableInsertUpdateSingleItem", myConnection))
{
myCommand.CommandType = CommandType.StoredProcedure;

if (myTeacherOtherSkillsTable.TeacherOtherSkillsKey == -1)
{myCommand.Parameters.AddWithValue("@teacherOtherSkillsKey", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@teacherOtherSkillsKey", myTeacherOtherSkillsTable.TeacherOtherSkillsKey);
}
if (myTeacherOtherSkillsTable.UserAccountKey == null){
myCommand.Parameters.AddWithValue("@userAccountKey", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@userAccountKey", myTeacherOtherSkillsTable.UserAccountKey);
}
if (myTeacherOtherSkillsTable.SkillName == null){
myCommand.Parameters.AddWithValue("@skillName", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@skillName", myTeacherOtherSkillsTable.SkillName);
}
if (myTeacherOtherSkillsTable.Organization == null){
myCommand.Parameters.AddWithValue("@organization", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@organization", myTeacherOtherSkillsTable.Organization);
}
if (myTeacherOtherSkillsTable.NoOfYear == null){
myCommand.Parameters.AddWithValue("@noOfYear", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@noOfYear", myTeacherOtherSkillsTable.NoOfYear);
}
if (myTeacherOtherSkillsTable.SkillLevel == null){
myCommand.Parameters.AddWithValue("@skillLevel", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@skillLevel", myTeacherOtherSkillsTable.SkillLevel);
}
if (myTeacherOtherSkillsTable.Others == null){
myCommand.Parameters.AddWithValue("@others", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@others", myTeacherOtherSkillsTable.Others);
}
if (myTeacherOtherSkillsTable.Status == null){
myCommand.Parameters.AddWithValue("@status", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@status", myTeacherOtherSkillsTable.Status);
}
if (myTeacherOtherSkillsTable.CreatedDateTime == null){
myCommand.Parameters.AddWithValue("@createdDateTime", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@createdDateTime", myTeacherOtherSkillsTable.CreatedDateTime);
}
if (myTeacherOtherSkillsTable.ModifiedDateTime == null){
myCommand.Parameters.AddWithValue("@modifiedDateTime", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@modifiedDateTime", myTeacherOtherSkillsTable.ModifiedDateTime);
}

DbParameter returnValue;
returnValue = myCommand.CreateParameter();
returnValue.Direction = ParameterDirection.ReturnValue;
myCommand.Parameters.Add(returnValue);

myConnection.Open();
myCommand.ExecuteNonQuery();
result = Convert.ToInt32(returnValue.Value);
myConnection.Close();
}
}
return result;
}

/// <summary>
/// Deletes a TeacherOtherSkillsTable from the database.
/// </summary>
/// <param name="teacherOtherSkillsKey">The TeacherOtherSkillsKey of the TeacherOtherSkillsTable to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
public static bool Delete(int teacherOtherSkillsKey)
{
int result = 0;
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
{
using (SqlCommand myCommand = new SqlCommand("sprocTeacherOtherSkillsTableDeleteSingleItem", myConnection))
{
myCommand.CommandType = CommandType.StoredProcedure;

myCommand.Parameters.AddWithValue("@teacherOtherSkillsKey", teacherOtherSkillsKey);
myConnection.Open();
result = myCommand.ExecuteNonQuery();
myConnection.Close();
}
}
return result > 0;
}

#endregion

/// <summary>
/// Initializes a new instance of the TeacherOtherSkillsTable class and fills it with the data fom the IDataRecord.
/// </summary>
private static TeacherOtherSkillsTable FillDataRecord(IDataRecord myDataRecord )
{
TeacherOtherSkillsTable myTeacherOtherSkillsTable = new TeacherOtherSkillsTable();
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("TeacherOtherSkillsKey")))
{
myTeacherOtherSkillsTable.TeacherOtherSkillsKey = myDataRecord.GetInt32(myDataRecord.GetOrdinal("TeacherOtherSkillsKey"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("UserAccountKey")))
{
myTeacherOtherSkillsTable.UserAccountKey = myDataRecord.GetInt32(myDataRecord.GetOrdinal("UserAccountKey"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("SkillName")))
{
myTeacherOtherSkillsTable.SkillName = myDataRecord.GetString(myDataRecord.GetOrdinal("SkillName"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Organization")))
{
myTeacherOtherSkillsTable.Organization = myDataRecord.GetString(myDataRecord.GetOrdinal("Organization"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("NoOfYear")))
{
myTeacherOtherSkillsTable.NoOfYear = myDataRecord.GetString(myDataRecord.GetOrdinal("NoOfYear"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("SkillLevel")))
{
myTeacherOtherSkillsTable.SkillLevel = myDataRecord.GetString(myDataRecord.GetOrdinal("SkillLevel"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Others")))
{
myTeacherOtherSkillsTable.Others = myDataRecord.GetString(myDataRecord.GetOrdinal("Others"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Status")))
{
myTeacherOtherSkillsTable.Status = myDataRecord.GetInt16(myDataRecord.GetOrdinal("Status"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("CreatedDateTime")))
{
myTeacherOtherSkillsTable.CreatedDateTime = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("CreatedDateTime"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("ModifiedDateTime")))
{
myTeacherOtherSkillsTable.ModifiedDateTime = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("ModifiedDateTime"));
}
return myTeacherOtherSkillsTable;
}
}
